
const express = require('express')
const router = express.Router()
const db = require('../mysql/index')
const path = require('path')
const fs = require('fs')

// 登录接口
router.post('/login', (req, res) => {
    const params = req.body
    console.log(params)
    const sqpStr = 'select * from users where username=?'
    db.query(sqpStr, [params.username], (err, result) => {
        if (err) {
            throw new Error(err)
        }
        // console.log(result)
        if (!result.length) { return res.json({ code: 200, message: '没有该账号,请先注册.', data: null }) }
        else {
            if (result[0].password == params.password) {
                if (result[0].status == 1) {
                    return res.status(200).send({ code: 403, message: '该账号已被禁用,请联系管理员.', data: null })
                }
                res.json({code: 200, message: "登录成功.", data: null })
            } else {
                const data = { code: 401, message: "密码错误.", data: null };
                res.json(data);
            }
        }
    })
})
// 注册接口
router.post("/register",(req,res)=>{
    const params = req.body
    console.log("🚀 ~ file: user.js:35 ~ router.get ~ params:", params)
    res.json()
})

module.exports = router